<!--
模板继承：使用job_home的样式
 -->
{% extends 'jobs_home.html' %}
{% block title %}职位查询{% endblock %}
{% block content %}
    {% load static %}
    <script src="{% static 'js/my.js' %}"></script>
    <script>
        var type = "请选择";
        {#        $(function () {#}
        {#            $("#list").on("click", ".xiangqing", function () {#}
        {##}
        {#                $.get("/setSession", {#}
        {#                    'pno': $(this).parents("tr").children().eq(1).text(),#}
        {#                    'cno': $(this).parents("tr").children().eq(0).text()#}
        {#                }, function (ret) {#}
        {#                    window.open("http://localhost:8099/desc_position");#}
        {#                });#}
        {#            });#}
        {#        });#}
        function update() {
            $.get("/job_search_update", {
                'keyword': $("#keyword").val(),
                'grad': $("#grad").val(),
                'salary': $("#salary").val(),
                'indus': $("#dustry2").val(),
                'loc': $("#area").val(),
                'type': type
            }, function (ret) {
                if (ret) {
                    var cot = "共找到" + ret.count + "条记录";
                    $("#count").html(cot);
                    var str = "";
                    $.each(ret.data, function (index, row) {
                        str += "<tr>";
                        $.each(row, function (i, data) {
                            if (i == 3) {
                                var grads = ["博士", "硕士", "本科", "专科", "大专", "高中", "不限", "经验不限", "不限", "中专及以下"];
                                str += "<td align=\"center\">" + grads[parseInt(data)] + "</td>";
                            }
                            else if (i == 6) {
                                str += "<td align=\"center\"><a class=\"xiangqing\"  href=\"http://localhost:8099/desc_position?id=" + data + "\">详情</a></td>";
                            }
                            else {
                                str += "<td align=\"center\">" + data + "</td>";
                            }

                        });

                    });
                    $("#list").html(str);

                    var pageCount = ret.len; //取到pageCount的值(把返回数据转成object类型)
                    var currentPage = 1; //得到urrentPage
                    var options = {
                        bootstrapMajorVersion: 3, //版本
                        currentPage: currentPage, //当前页数
                        totalPages: pageCount, //总页数
                        itemTexts: function (type, page, current) {
                            switch (type) {
                                case "first":
                                    return "首页";
                                case "prev":
                                    return "上一页";
                                case "next":
                                    return "下一页";
                                case "last":
                                    return "末页";
                                case "page":
                                    return page;
                            }
                        },//点击事件，用于通过Ajax来刷新整个list列表
                        onPageClicked: function (event, originalEvent, type, page) {
                            $.get("/getpositionpage", {'index': page}, function (ret) {
                                if (ret) {
                                    var str = "";
                                    $.each(ret.data, function (index, row) {
                                        str += "<tr>";
                                        $.each(row, function (i, data) {
                                            if (i == 3) {
                                                var grads = ["博士", "硕士", "本科", "专科", "大专", "高中", "不限", "经验不限", "不限", "中专及以下"];
                                                str += "<td align=\"center\">" + grads[parseInt(data)] + "</td>";}
                                            else
                                                if (i == 6) {
                                                    str += "<td align=\"center\"><a class=\"xiangqing\"  href=\"http://localhost:8099/desc_position?id=" + data + "\">详情</a></td>";
                                                }
                                                else {
                                                    str += "<td align=\"center\">" + data + "</td>";
                                                }

                                            }
                                            );
                                    });
                                    $("#list").html(str);
                                }
                            })
                        }
                    };
                    $("#page").bootstrapPaginator(options);
                }
            })
        }

        $(function () {
            var pageCount = {{ pagecount }}; //取到pageCount的值(把返回数据转成object类型)
            var currentPage = {{ current }}; //得到urrentPage
            var options = {
                bootstrapMajorVersion: 3, //版本
                currentPage: currentPage, //当前页数
                totalPages: pageCount, //总页数
                itemTexts: function (type, page, current) {
                    switch (type) {
                        case "first":
                            return "首页";
                        case "prev":
                            return "上一页";
                        case "next":
                            return "下一页";
                        case "last":
                            return "末页";
                        case "page":
                            return page;
                    }
                },//点击事件，用于通过Ajax来刷新整个list列表
                onPageClicked: function (event, originalEvent, type, page) {
                    $.get("/getpositionpage", {'index': page}, function (ret) {
                        if (ret) {
                            var str = "";
                            $.each(ret.data, function (index, row) {
                                str += "<tr>";
                                $.each(row, function (i, data) {
                                    if (i == 3) {
                                        var grads = ["博士", "硕士", "本科", "专科", "高中", "不限","经验不限", "不限", "中专及以下"];
                                        str += "<td align=\"center\">" + grads[parseInt(data) - 1] + "</td>";
                                    }else if  (i == 6) {
                                 str += "<td align=\"center\"><a class=\"xiangqing\"  href=\"http://localhost:8099/desc_position?id=" + data + "\">详情</a></td>";
                            }
                            else  {
                                str += "<td align=\"center\">" + data + "</td>";
                            }

                        });
                            });
                            $("#list").html(str);
                        }
                    })
                }
            };
            $("#page").bootstrapPaginator(options);
        });
        $(document).ready(function () {
            $("#shixi").click(function () {
                $("#type").text("实习");
                type = "实习";
                update();
            });
            $("#quanzhi").click(function () {
                $("#type").text("全职");
                type = "全职";
                update();
            });
            $("#searchfor").click(function () {
                update();
            });
            /*
             $("#type").click(function () {
             update();
             });
             $("#dustry2").click(function () {
             update();
             });
             $("#area").click(function () {
             update();
             });
             $("#salary").click(function () {
             update();
             });
             $("#grad").click(function () {
             update();
             });*/
        });
    </script>
    <div class="container">
        <div class="row">
            <div class="col-lg-3">
            </div>
            <form method="post" id="search">
                {% csrf_token %}
                <div class="col-lg-6">
                    <div class="input-group">
                        <div class="input-group-btn">
                            <button id="type" class="btn btn-default">请选择</button>
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu">
                                <li><a href="#" id="shixi">实习</a></li>
                                <li><a href="#" id="quanzhi">全职</a></li>
                            </ul>
                        </div>
                        <input id="keyword" type="text" class="form-control" placeholder="输入关键字"/>
                        <span class="input-group-btn">
                         <button id="searchfor" class="btn btn-primary" type="button">搜索</button>
                    </span>
                    </div>
                </div>
            </form>
            <div class="col-lg-3">
            </div>
        </div>
        <div class="row">
            <form method="post" id="update">
                <table class="table">
                    <tbody>
                    <tr>
                        <td align="right">
                            一级行业：
                        </td>
                        <td align="left">
                            <select id="dustry1" name="dustry1"
                                    onchange="getsecondindustry(this.options[this.options.selectedIndex].value)">
                                {% for d in indusrylist %}
                                    <option value="{{ d.code }}">{{ d.name }}</option>
                                {% endfor %}
                            </select>
                        </td>
                        <td align="right">
                            二级行业：
                        </td>
                        <td align="left">
                            <select id="dustry2" name="dustry2" onchange="update()">
                                <option value="-1">请选择</option>
                            </select>
                        </td>
                    </tr>

                    <tr>
                        <td align="right">
                            薪资：
                        </td>
                        <td align="left">
                            <select id="salary" name="salary" onchange="update()">
                                <option value="-1">请选择</option>
                                <option value="1">0-5000</option>
                                <option value="2">5000-10000</option>
                                <option value="3">10000-15000</option>
                                <option value="4">15000-20000</option>
                                <option value="5">0-10000</option>
                                <option value="6">10000-20000</option>
                                <option value="7">20000以上</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            所在省：
                        </td>
                        <td align="left">
                            <select id="pro" name="pro"
                                    onchange="getcity(this.options[this.options.selectedIndex].value)">
                                {% for p in provincelist %}
                                    <option value="{{ p.code }}">{{ p.name }}</option>
                                {% endfor %}
                            </select>
                        </td>
                        <td align="right">
                            所在市：
                        </td>
                        <td align="left">
                            <select id="city" name="city"
                                    onchange="getarea(this.options[this.options.selectedIndex].value)">
                                <option value="-1">请选择</option>
                            </select>
                        </td>
                        <td align="right">
                            所在区县：
                        </td>
                        <td align="left">
                            <select id="area" name="area" onchange="update()">
                                <option value="-1">请选择</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            要求学历：
                        </td>
                        <td align="left">
                            <select id="grad" name="grad" onchange="update()">
                                <option value="-1">请选择</option>
                                <option value="1">博士</option>
                                <option value="2">硕士</option>
                                <option value="3">本科</option>
                                <option value="4">专科</option>
                                <option value="5">高中</option>
                                <option value="6">其他</option>
                            </select>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </form>
            <div>
                <p id="count">共找到{{ count }}条记录</p>
            </div>
        </div>
        <div class="row">
            <div style="background: white">
                <table class="table table-hover" style="border-collapse:separate; border-spacing:0px 10px;">
                    <thead>
                    <tr>
                        <td align="center">公司名</td>
                        <td align="center">职位</td>
                        <td align="center">薪资</td>
                        <td align="center">学历要求</td>
                        <td align="center">工作地点</td>
                        <td align="center">发布时间</td>
                        <td align="center">查看详情</td>
                        <td>
                        </td>
                    </tr>
                    </thead>
                    <tbody id="list">
                    {% for po in postions %}
                        <tr>

                            <td align="center">{{ po.1 }}</td>
                            <td align="center">{{ po.2 }}</td>
                            <td align="center">{{ po.3 }}</td>
                            <td align="center">{{ po.4 }}</td>
                            <td align="center">{{ po.5 }}</td>
                            <td align="center">{{ po.6 }}</td>
                            <td align="center"><a class="xiangqing"
                                                  href="http://127.0.0.1:8099/desc_position?id={{ po.7 }}">详情</a>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-7">
            </div>
            <div class="col-lg-5">
                <ul id="page">
                </ul>
            </div>
        </div>
    </div>
{% endblock %}